﻿using System;
using System.ComponentModel;

namespace Brjnk.GpxExplorer.Workspace.BitmapExport
{
    public class Page : INotifyPropertyChanged
    {
        private AreaManager area;

        public Page(AreaManager area)
        {
            this.area = area;
            area.Area.SizeChanged += new System.Windows.SizeChangedEventHandler(Area_SizeChanged);
            this.Width = area.Area.ActualWidth;
            this.Height = area.Area.ActualHeight;
        }

        private double width;

        public double Width
        {
            get { return width; }
            private set { width = value; OnPropertyChanged("Width"); }
        }

        private double height;

        public double Height
        {
            get { return height; }
            private set { height = value; OnPropertyChanged("Height"); }
        }

        private void Area_SizeChanged(object sender, System.Windows.SizeChangedEventArgs e)
        {
            this.Width = e.NewSize.Width;
            this.Height = e.NewSize.Height;
            OnSizeChanged();
        }

        public void Destroy()
        {
            area.Area.SizeChanged -= new System.Windows.SizeChangedEventHandler(Area_SizeChanged);
        }

        public event EventHandler SizeChanged;

        private void OnSizeChanged()
        {
            if (SizeChanged != null) SizeChanged(this, EventArgs.Empty);
        }

        public event PropertyChangedEventHandler PropertyChanged;

        private void OnPropertyChanged(string propertyName)
        {
            if (PropertyChanged != null) PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
        }
    }
}